
var colorArr = ["#5470C6", "#91CC75", "#FAC858", "#EE6666", "#73C0DE"];
// $(function () {
//     $('#db_Start').datebox('setValue', GetDateStr(-7));
//     $('#db_End').datebox('setValue', getCurrDate());
//     InitChart();
//     BindDatalist();
// });
// 用户ID
let id = getUrlParam("id");
$(function () {
    GetUserRole();
});
//获取用户权限
function GetUserRole() {
    // let thisdata = [];
    // thisdata.push(InitRole(id));
    let USERdata = InitRole(id);
    if (USERdata != null) {
        $('#db_Start').datebox('setValue', GetDateStr(-7));
        $('#db_End').datebox('setValue', getCurrDate());
        InitChart();
        BindDatalist();
    }
    else OpenErrmsg("../../web/errhtml/404.html");
}

//查询按钮
function SearchData() {
    initTitle();
    BindDatalist();
}
//重置按钮
function ReSearchData() {
    $('#db_Start').datebox('setValue', GetDateStr(-14));
    $('#db_End').datebox('setValue', getCurrDate());
    SearchData();
}
//加载图表
function InitChart() {

    let xAxis = ["1日", "2日", "3日", "4日", "5日"];
    let data = [
        { "code": "01", "name": "定员", "data": ["34", "617", "53", "54", "32"] },
        { "code": "02", "name": "VIP", "data": ["345", "167", "253", "564", "232"] },
        { "code": "03", "name": "空床位", "data": ["124", "671", "573", "504", "132"] },
        { "code": "04", "name": "外协", "data": ["345", "167", "253", "564", "232"] }
    ];

    var myChart = echarts.init(document.getElementById('chartdiv'));
    var xAxisDataLine = new Array();
    var seriesDataLine = new Array();
    for (var i = 0; i < data.length; i++) {
        var item = data[i];
        xAxisDataLine.push(item.name)
        seriesDataLine.push({
            name: item.name,
            type: "bar",
            barWidth: 100,
            stack: '搜索引擎',
            // stack: 'Total',
            data: item.data
        });
    }
    console.log(xAxisDataLine)
    var option = {
        title: {
            text: ""
        },
        // 全局调色盘。
        color: ['#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
        legend: {
        },
        tooltip: {//过滤掉统计的series
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            // formatter: function(params){
            //     var res=params[0].name+"<br/>";
            //     for(let i=0;i<params.length-1;i++){
            //         res+=params[i].seriesName+":"+params[i].value+"<br/>"
            //     }
            //     return res;
            // }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                data: xAxis
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: seriesDataLine

    };
    myChart.setOption(option);
}

//加载设备列表信息
function BindDatalist() {
    let StartDate = $('#db_Start').datebox('getValue');
    let EndDate = $('#db_End').datebox('getValue');
    let daycount = DateDiff(StartDate, EndDate);
    if (StartDate != "" && EndDate != "" && daycount > 14) {
        $.messager.alert('警告', '查询日期不能超过两周！');
    } else {
        console.log('aaa')
        //后台返回数据
        var data = [
            { "The_Date": "2021-09-08", "Total_Num": "10", "Staffing_Num": "10", "VIP_Num": "2021", "Seat_Capacity_Num": "9", "ex_Assist_Num": "09" },
            { "The_Date": "2021-09-08", "Total_Num": "10", "Staffing_Num": "10", "VIP_Num": "2021", "Seat_Capacity_Num": "9", "ex_Assist_Num": "09" },
            { "The_Date": "2021-09-08", "Total_Num": "10", "Staffing_Num": "10", "VIP_Num": "2021", "Seat_Capacity_Num": "9", "ex_Assist_Num": "09" },
            { "The_Date": "2021-09-08", "Total_Num": "10", "Staffing_Num": "10", "VIP_Num": "2021", "Seat_Capacity_Num": "9", "ex_Assist_Num": "09" },
            { "The_Date": "2021-09-08", "Total_Num": "10", "Staffing_Num": "10", "VIP_Num": "2021", "Seat_Capacity_Num": "9", "ex_Assist_Num": "09" },
            { "The_Date": "2021-09-08", "Total_Num": "10", "Staffing_Num": "10", "VIP_Num": "2021", "Seat_Capacity_Num": "9", "ex_Assist_Num": "09" },
            { "The_Date": "2021-09-08", "Total_Num": "10", "Staffing_Num": "10", "VIP_Num": "2021", "Seat_Capacity_Num": "9", "ex_Assist_Num": "09" },
        ];
        //加载数据
        $('#dg_DateList').datagrid({
            data: data,
        });
    }
}
